package forum.view.managedbeans;

import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import forum.business.entities.UserBO;
import forum.business.facades.UserFacade;
import forum.util.exceptions.AdException;

public class UsersBean {

	private ListDataModel model = new ListDataModel();

	// private List<UserBO> users;

	public UsersBean() {
	}

	public DataModel getUsers() {
		UserFacade userFacade = new UserFacade();
		List<UserBO> users = null;
		try {
			users = userFacade.listUsers();
		} catch (AdException e) {
			System.err.println(e.getMessage());
		}
		model.setWrappedData(users);
		return model;
	}

	public String getFormatStatus() {
		
		UserBO userBO = (UserBO) model.getRowData();

		ResourceBundle resourceBundle = null;
		try {
			resourceBundle = ResourceBundle
					.getBundle("forum.util.messages.MessageResource");
		} catch (NullPointerException e) {
			System.err.println("Nici z Resource");
		} catch (MissingResourceException e) {
			System.err.println("Nie znalazlem resource");
		}
		
		try {

			switch (Integer.parseInt(userBO.getStatus())) {
			case 0:
				return resourceBundle.getString("user");
			case 1:
				return resourceBundle.getString("moderator");
			case 2:
				return resourceBundle.getString("administrator");
			default:
				return "Unknown";
			}
			
		} catch (Exception e) {
			return resourceBundle.getString("unknown");
		}
	}
	/*
	 * public void setUsers(List<UserBO> users) { this.users = users; }
	 */
}
